/**
* @description: 908. 最小差值 I
* @author hewei
* @date 2022/9/20 14:29
* @version 1.0
*/

public class SmallestRangeI {

    public int smallestRangeI(int[] nums, int k) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for (int num : nums) {
            max = Math.max(max, num);
            min = Math.min(min, num);
        }
        return max - min > 2 * k ? max - min - 2 * k : 0;
    }
}
